package com.pf.rule.controller;

import com.pf.common.dto.BaseResult;
import com.pf.rule.dto.RuleAddReq;
import com.pf.rule.dto.RuleUpdateReq;
import com.pf.rule.service.RuleService;
import com.pf.common.utils.BaseResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author PanFei
 * @version 1.0.0
 * @createTime 2022/7/7 23:36
 */
@RestController
@RequestMapping("/rule")
public class RuleController {

    @Autowired
    private RuleService ruleService;

    @PostMapping("/add")
    public BaseResult add(@RequestBody RuleAddReq ruleReq) {
        ruleService.addRule(ruleReq);
        return BaseResultUtils.success();
    }

    @PostMapping("/update")
    public BaseResult update(@RequestBody RuleUpdateReq ruleReq) {
        ruleService.updateRule(ruleReq);
        return BaseResultUtils.success();
    }

    @GetMapping("/delete/{id}")
    public BaseResult delete(@PathVariable("id") Integer id) {
        ruleService.deleteRule(id);
        return BaseResultUtils.success();
    }

    @GetMapping("/recover/{id}")
    public BaseResult recover(@PathVariable("id") Integer id) {
        ruleService.recoverRule(id);
        return BaseResultUtils.success();
    }

}
